package com.breaktian.hybrid.base;

import android.app.Activity;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;

import java.util.HashMap;

/**
 * Created by keke.tian on 2018/2/5.
 */

public class BaseCordovaPlugin extends CordovaPlugin {
    private Activity mActivity;
    protected HashMap<String, BaseCordovaAction> mActionMap = new HashMap<>();

    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);
        mActivity = cordova.getActivity();
    }

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        return mActionMap.get(action).execAction(this,mActivity,args,callbackContext);
    }

}
